package com.zmc.member.exception.handler;

import com.zmc.common.utils.R;
import com.zmc.member.exception.*;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author：zmc
 * @Date：2024/11/11 15:27
 */

@ControllerAdvice
@ResponseBody
public class MemberExceptionHandler {

    @ExceptionHandler(value = ShoppingCartNullException.class)
    public R shoppingCartNullExceptionHandler(ShoppingCartNullException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = MemberNotExistsException.class)
    public R memberNotExistsExceptionExceptionHandler(MemberNotExistsException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = MemberPasswordNotMatchException.class)
    public R memberPasswordNotMatchExceptionHandler(MemberPasswordNotMatchException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = PhoneCodeException.class)
    public R memberPhoneCodeExceptionHandler(PhoneCodeException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = AddressMaxCountException.class)
    public R addressMaxCountExceptionHandler(AddressMaxCountException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = MemberEmailRepeatException.class)
    public R memberEmailRepeatExceptionHandler(MemberEmailRepeatException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = MemberUsernameRepeatException.class)
    public R memberUsernameRepeatExceptionHandler(MemberUsernameRepeatException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = PhoneCodeRepeatException.class)
    public R phoneCodeRepeatExceptionHandler(PhoneCodeRepeatException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = MemberPwdException.class)
    public R memberPwdExceptionHandler(MemberPwdException exception) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }
}
